<template>
  <div class="box">
    <Hand :left="true" :iconbool="false" title="回收订单" @back="fn"></Hand>

    <!-- 回收订单 -->
    <van-tabs v-model:active="active" background="#2bcddc" title-inactive-color="white" title-active-color="white"
      class="vantabs" :sticky="true" offset-top="59" @click-tab="fun5">
      <van-tab title="待接单">
        <OrdertoreceiveVue @btnTix="tixing" @btnTix1="tixing1" @btnTix2="waitrouter"></OrdertoreceiveVue>
      </van-tab>
      <van-tab title="已接单">
        <OrdertoreceiveVue Btntext1="致电收货员" @btnTix="callrouter" @btnTix1="tixing1" @btnTix2="callrouter">
        </OrdertoreceiveVue>
      </van-tab>
      <van-tab title="回收中">
        <OrdertoreceiveVue :Btnfalg="false" :Btnfalg1="false" @btnTix2="callrouter1"></OrdertoreceiveVue>
      </van-tab>
      <van-tab title="已完成">
        <OrdertoreceiveVue :Btnfalg="false" Btntext="立即评价" @btnTix1="Listrouter" @btnTix2="waitrouter">
        </OrdertoreceiveVue>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter, useRoute } from "vue-router";
import OrdertoreceiveVue from "./Mycomponents/Recallordercelive.vue";
import { showToast } from "vant";
import { showConfirmDialog, showSuccessToast } from "vant";
import { useLoginStore } from "../../stores/login"
import Hand from "../../components/Hand.vue";
import {useCounterStore} from "../../stores/counter"
import { getUnpaid,getReorder } from "../../api/index";
import { ExchangeInfo } from "../../stores/ExchangeOrder";

const stores = useLoginStore()
const stores1  = ExchangeInfo()

const active = ref(0);

const route = useRoute();
const router = useRouter();


active.value = Number(route.query.num);

const tixing = () => {
  showToast("已向门店发送接单提醒");
};

function fn() {
  router.back();
}

const fun5 = (a) => {

  if (a.title == "待接单") {
    getReorder(localStorage.token, "待支付").then((res) => {
      stores1.data = res.data.data.data;
    });
  } else if (a.title == "已接单") {
    getReorder(localStorage.token, "待取货").then((res) => {
      stores1.data = res.data.data.data;
    });
  }else if( a.title == "回收中" ){
    getReorder(localStorage.token, "配送中").then((res) => {
      stores1.data = res.data.data.data;
  });
  }else if( a.title == "已完成"  ){
    getReorder(localStorage.token, "已完成").then((res) => {
      stores1.data = res.data.data.data;
  });
  }
};

const tixing1 = () => {
  
  showConfirmDialog({
    title: "订单取消",
    confirmButtonText: "立即取消",
    cancelButtonText: "暂不取消",
    confirmButtonColor: "black",
    cancelButtonColor: "#f95474",
    message:
      "门店人员可能正忙，请确认是否取消订单或等待时间结束后自动取消订单。",
  })
    .then(() => {

      showSuccessToast("取消成功");
    })
    .catch(() => {

    });
};
const Listrouter = () => {
  
  router.replace("/Myappraise");
};

const callrouter = () => {

  router.replace("/Callreceivingclerk");
};

const waitrouter = () => {
  router.push({
    path: "/Waitorderreceiving",
    query: {
      name: "OMINI来福士广场店",
      site: "上海市来福士广场1层32号",
      tab: "新店",
      tab1: "营业中",
      childstate: "等待接单",
      olgstate: "门店详情",
    },
  });
};

const callrouter1 = () => {
  router.push({
    path: "/Waitorderreceiving",
    query: {
      name: "赵师傅",
      site: "13255486659",
      tab: "诚信",
      tab1: "服务好",
      childstate: "正在回收",
      olgstate: "配送员详情",
    },
  });
};
</script>

<style lang="less" scoped>

</style>
